<template>
    <view>
        <u-form-item :key="item.key" :label="$t(item.label)" :required="item.required">
            <u-checkbox-group @change="checkboxGroupChange" :width="lang=='ru'?'100%':'50%'">
                <u-checkbox
                    v-model="item.checked"
                    v-for="(item, index) in checkboxList" :key="index"
                    :name="item.name"
                >{{ $t(item.name) }}
                </u-checkbox>
            </u-checkbox-group>
        </u-form-item>
    </view>
</template>
<script>
export default {
    props: {
        item: {
            type: Object,
            default: {},
            required: true
        }
    },
    data() {
        return {
            lang: getApp().globalData.lang,
            type: 'default',
            radio: '否',
            checkboxList: [],
        };
    },
    mounted() {
        if (this.item.details && this.item.details.type) {
            this.type = this.item.details.type
        }
        this.setDefaultValue()
    },
    methods: {
        setDefaultValue() {// 设置默认值
            const values = this.item.value.value.split(',')
            const lists = this.item.value.text.split(',')
            for (let i = 0; i < lists.length; i++) {
                let checked = values.indexOf(lists[i]) !== -1 ? true : false
                let arr = {
                    name: lists[i],
                    checked: checked
                }
                this.checkboxList.push(arr)
            }
        },
        checkboxGroupChange(e) {
            console.log('checkboxGroupChange', e)
            const checkValue = e.join(',')
            this.$emit('change', this.item.key, checkValue)
        },
    }
}
</script>

<style lang="scss">
</style>
